<?php


namespace App\Org;

use App\Models\Admin\AdminSetting;

$express_bird_apikey=AdminSetting::where('name','express_bird_apikey')->value('value');
$express_bird_userid=AdminSetting::where('name','express_bird_userid')->value('value');
define('express_bird_apikey',$express_bird_apikey??'');
define('express_bird_userid',$express_bird_userid??'');

class ExpressBird
{
    const url_query_express='https://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx';//及时查询

    const request_base=[
        'EBusinessID'=>express_bird_userid,//用户 ID
        'DataType'=>'2',//数据为json
    ];

    /**
     *  生成请求签名
     */
    public static function getSign($data)
    {
        $sign=urlencode(base64_encode(md5(json_encode($data).express_bird_apikey)));
        return $sign;
    }

    //查询快递
    public static function queryExpressInfo($data)
    {
        $data_all=self::request_base;
        $data_all['RequestData']=json_encode($data);
        $data_all['RequestType']=1002;
        $data_all['DataSign']=self::getSign($data);
        $url=self::url_query_express.'?'.http_build_query($data_all);
        $res=json_decode(zc_curl($url));
        if($res->Success===false)
        {
            throw new \Exception($res->Reason,-1);
        }
        return $res;
    }
}
